import Vue from 'vue'
import Vuex from 'vuex'

import organization from './organization'


// 创建模块
function creatModel (mod:any):any{
    return {
        namespaced: true,
        ...(new mod())
    }
}


class indexStore{


    _setModuel (key,mod){
        this.modules[key] = creatModel(mod);
    }

    state = {

        _reqStatus: () => true,
        
    }

    modules = {
        organizationStore: creatModel(organization),
    }
    
    mutations = {

        // 设置模拟请求返回状态
        _setReqStatus(state, statusFn){
            state['_reqStatus'] = statusFn;
        }
        
    }
    
    actions = {

        // 模拟请求成功或失败的返回
        request ({commit, state, dispatch}, data){
            return state._reqStatus(data);
        }

    }
    
}

Vue.use(Vuex);
const store = new Vuex.Store(new indexStore());

export {store, indexStore} ;